<?php
require_once("database.php");
class xl_chi_tiet_hoa_don extends database
{
	function danh_sach($vi_tri, $so_luong)
	{
		$vi_tri = intval($vi_tri);
		$so_luong = intval($so_luong);
		$sql = "select * from chi_tiet_hoa_don limit $vi_tri, $so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	function so_luong()
	{
		$sql = "select count(*) from chi_tiet_hoa_don";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function xem($ma)
	{
		$ma = intval($ma);

		$sql = "select * from chi_tiet_hoa_don where ma = '$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function ds_hoa_don($ma_hoa_don)
	{
		$ma_hoa_don = intval($ma_hoa_don);

		$sql = "select * from chi_tiet_hoa_don where ma_hoa_don = '$ma_hoa_don'";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	function xoa($ma)
	{
		$ma = intval($ma);

		$sql = "delete from chi_tiet_hoa_don where ma = '$ma'";
		$this->setQuery($sql);
		$this->query();
	}
	function them($ma_hoa_don, $ma_san_pham, $ten_san_pham, $so_luong, $don_gia, $thanh_tien)
	{
		$ma_hoa_don = intval($ma_hoa_don);
		$ma_san_pham = intval($ma_san_pham);
		$ten_san_pham = addslashes($ten_san_pham);
		$so_luong = intval($so_luong);
		$don_gia = intval($don_gia);
		$thanh_tien = intval($thanh_tien);

		$sql = "INSERT INTO chi_tiet_hoa_don(ma_hoa_don,ma_san_pham,ten_san_pham,so_luong,don_gia,thanh_tien) VALUES ('$ma_hoa_don','$ma_san_pham','$ten_san_pham','$so_luong','$don_gia','$thanh_tien')";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat($ma, $ma_hoa_don, $ma_san_pham, $ten_san_pham, $so_luong, $don_gia, $thanh_tien)
	{
		$ma = intval($ma);
		$ma_hoa_don = intval($ma_hoa_don);
		$ma_san_pham = intval($ma_san_pham);
		$ten_san_pham = addslashes($ten_san_pham);
		$so_luong = intval($so_luong);
		$don_gia = intval($don_gia);
		$thanh_tien = intval($thanh_tien);

		$sql ="UPDATE chi_tiet_hoa_don SET ma_hoa_don= '$ma_hoa_don', ma_san_pham= '$ma_san_pham', ten_san_pham= '$ten_san_pham', so_luong= '$so_luong', don_gia= '$don_gia', thanh_tien= '$thanh_tien' WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function tim_kiem ($tu_khoa)
	{
		$sql = "select * from chi_tiet_hoa_don where	$ten_san_pham like %tu_khoa%"; 
		$this->setQuery($sql);
		return $this->loadAllRow();	
	}
 }
?>